/*
 * Inode.h
 *
 *  Created on: Apr 19, 2011
 *      Author: Marc Kampherbeek
 */

#ifndef INODE_H_
#define INODE_H_

#include "Types.h"
#include "InodeBlock.h"
#include "ino.h"
#include "DataBlock.h"
#include "InDir1Block.h"
#include "InDir2Block.h"
#include "InDir3Block.h"
#include <list>

using namespace std;

class Inode {
private:
	InodeBlock *	myBlock;	//link to the actual block
	ino_x			inr;	 	//inode number
	int				activity;	//how many times used in AIT

	//content in disk order
	int		mode;				// type of file and permissions
	int		links; 				// number of hard links to this inode
	int		uid; 				// User ID (owner)
	int 	gid;				// Group ID (group/rank of owner)
	long	size;				// file size in bytes
	long	addr[13];			// disk block addresses
	long	aTime;				// last access time
	long	mTime;				// last modification time
	long	cTime;				// creation time
	//end of content

	InDir1Block* inDir1;
	InDir2Block* inDir2;
	InDir3Block* inDir3;

public:
	Inode(InodeBlock *, ino_x);
	virtual ~Inode();
	int		getMode()			{ return mode;		};
	ino_x	getInodeNr()		{ return inr;		};
	int		getLinks()			{ return links;		};
	int		getOwner()			{ return uid;		};
	int		getGroup()			{ return gid;		};
	long	getSize()			{ return size;		};
	long	getATime()			{ return aTime;		};
	long	getmTime()			{ return mTime;		};
	long	getcTime()			{ return cTime;		};
	long	getBlock(int x)		{ return addr[x];	};
	int		getActivity()		{ return activity;	};
	void 	setActivity(int x) 	{ activity = x;		};
	list<long> * getFileData();
	string modeString();

	void setMode(int);
	void increaseLinkCount();
	void decreaseLinkCount();
	void setLinks(int i){ links = i; };
	void writeLinks();
	void setOwner(int);
	void setGroup(int);
	void setSize(long);
	void setAddr(int, long);
	void setLastAccessTime();
	void setLastModifiedTime();
	void setCreatedTime();
	void writeTime(int);

	int getDiskBlockNr(int);
	void parseInodeBlock();
	void print();
	void write();
	void reset();
	void free();
};

#endif /* INODE_H_ */
